﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace TextEditor.TextDocument.Control
{
    public enum BorderStyle
    {
        top, bottom, left, right, leftSlash, rightSlash
    }

    public class CustomBorderButton : System.Windows.Forms.Control
    {
        BorderStyle borderStyle;
        public BorderStyle BoderType
        {
            get
            {
                return borderStyle;
            }
            set
            {
                borderStyle = value;
            }
        }

        bool isSelected = false;

        public bool Selected
        {
            get { return isSelected; }
            set
            {
                isSelected = value;
                this.BackColor = value ? Color.LightGray : Color.White;
            }
        }

        protected override void OnClick(EventArgs e)
        {
            this.Selected = !this.isSelected;
            if (this.Parent is Form)
            {
                ((Form)this.Parent).Refresh();
            }
            base.OnClick(e);
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            using (Pen pen = new Pen(Color.Black))
            {
                switch (borderStyle)
                {
                    case BorderStyle.left:
                        e.Graphics.DrawLine(pen, 0, 0, 0, this.Height);
                        break;
                    case BorderStyle.right:
                        e.Graphics.DrawLine(pen, Width - 1, 0, Width - 1, this.Height);
                        break;
                    case BorderStyle.top:
                        e.Graphics.DrawLine(pen, 0, 0, Width, 0);
                        break;
                    case BorderStyle.bottom:
                        e.Graphics.DrawLine(pen, 0, this.Height - 1, Width, Height - 1);
                        break;
                    case BorderStyle.leftSlash:
                        e.Graphics.DrawLine(pen, 0, 0, Width, Height);
                        break;
                    case BorderStyle.rightSlash:
                        e.Graphics.DrawLine(pen, Width, 0, 0, Height);
                        break;
                }
            }
        }
    }
}
